using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using System.Data.SqlClient;
using SpringWaterDataAccess;

namespace client
{
	/// <summary>
	/// Summary description for bloggercomments.
	/// </summary>
	public partial class bloggercomments : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.CheckBox CheckBox1;

		protected int userID = 0;
	
		protected void Page_Load(object sender, System.EventArgs e)
		{
			// Put user code to initialize the page here
			userID = Convert.ToUInt16(Request.QueryString["UserID"]);
			// Put user code to initialize the page here
			if (!IsPostBack) 
			{
				BindData(20);
			}
		}

		private void BindData(int rows) 
		{
			ForumDataAccess da = new ForumDataAccess();
			int totalRecords = 0;

			DataSet ds = 
				da.getRepliesByUserID(userID,1,rows,out totalRecords,"blog","Active",0,"CreateDate");

			MyRepeater.DataSource = ds;
			MyRepeater.DataBind();
		}

		

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    

		}
		#endregion

		
		protected void Button2_Click(object sender, System.EventArgs e)
		{
		
		}

		protected void Button3_Click(object sender, System.EventArgs e)
		{
		
		}

		protected void Button4_Click(object sender, System.EventArgs e)
		{
		        
		}

		protected void Button5_Click(object sender, System.EventArgs e)
		{
			
		}

		protected void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			int selectedValue = Convert.ToUInt16(DropDownList1.SelectedValue);
			BindData(selectedValue);
		}

        protected void Button1_Click1(object sender, EventArgs e)
        {
            Response.Redirect("bloggerhome.aspx?userID=" + userID);
        }

        protected void Button2_Click1(object sender, EventArgs e)
        {
            Response.Redirect("bloggerinput.aspx?userID=" + userID);
        }

        protected void Button3_Click1(object sender, EventArgs e)
        {
            Response.Redirect("bloggerarticles.aspx?userID=" + userID);
        }

        protected void Button5_Click1(object sender, EventArgs e)
        {
            foreach (RepeaterItem myitem in MyRepeater.Items)
            {
                foreach (Control c in myitem.Controls)
                {
                    if (c is CheckBox)
                    {
                        CheckBox cb = (CheckBox)c;

                        if ((cb.Checked))
                        {
                            // Each row has a invisible Label for dispalying word ID
                            Label idLabel = (Label)myitem.FindControl("Label1");

                            if (idLabel != null)
                            {
                                //Response.Write(idLabel.Text + "<br>");
                                ForumDataAccess da = new ForumDataAccess();
                                da.DeletePost(Convert.ToInt16(idLabel.Text));

                            }
                        }
                    }

                }
            }

            BindData(20);
        }

        protected void Button4_Click1(object sender, EventArgs e)
        {
            Response.Redirect("bloggercomments.aspx?userID=" + userID);
        }
	}
}
